package cn.wizzer.app.task.commons.ext.quartz.job;

import cn.wizzer.app.user.modules.models.UserAccountRecord;
import cn.wizzer.app.user.modules.services.account.UserAccountRecordService;
import cn.wizzer.app.user.modules.services.account.UserAccountRecordStatisticsService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

/**
 * @author zl
 * @date 2020/6/17 9:56
 */
@IocBean
public class UserAccountRecordStatisticsJob implements Job {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private UserAccountRecordStatisticsService userAccountRecordStatisticsService;
    @Inject
    @Reference
    private UserAccountRecordService userAccountRecordService;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("统计用户流水记录开始");
        boolean flag = true;
        while (flag) {
            userAccountRecordStatisticsService.statistics();
            //判断是否还存在未统计数据，存在则继续
            flag = userAccountRecordService.count(Cnd.where("counted", "=", 0)
                    .and("delFlag", "=", 0)) > 0;
        }
        log.info("统计用户流水记录结束");
    }
}
